//
//  MineLogic.m
//  UniversalApp
//
//  Created by voidcat on 2017/7/11.
//  Copyright © 2017年 voidcat. All rights reserved.
//

#import "MineLogic.h"

@implementation MineLogic
-(void)loadData
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_user_center_info"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    //[param setObject:@"" forKey:@""];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {

    } success:^(id responseObject) {
        _model = [UserCenterModel modelWithJSON:[responseObject valueForKey:@"data"]];
        if([self.delegagte respondsToSelector:@selector(requestDataCompleted)])
        {
            [self.delegagte requestDataCompleted];
        }
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];

}

+(void)requestSetDoNotDisturtWithBock:(CommonBlock )block
{
    [[HUDHelper sharedInstance] syncLoading:ASLocalizedString(@"请求中")];
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"request_set_do_not_disturb"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:curUser.id forKey:@"uid"];
    [param setObject:curUser.token forKey:@"token"];
    //type 1设置免打扰  2取消
    if(curUser.is_open_do_not_disturb == 0)
    {
        [param setObject:@"1" forKey:@"type"];
    }
    else
    {
        [param setObject:@"0" forKey:@"type"];
    }
    
    [CYNET POSTv3:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {

        
        NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_user_center_info"];
        NSMutableDictionary *param = [NSMutableDictionary dictionary];
        //[param setObject:@"" forKey:@""];
        
        [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
            
        } success:^(id responseObject) {
            [[HUDHelper sharedInstance] syncStopLoading];
            [MBProgressHUD showTopTipMessage:ASLocalizedString(@"设置成功")];
            
            UserCenterModel *model = [UserCenterModel modelWithJSON:[responseObject valueForKey:@"data"]];
            curUser.is_open_do_not_disturb = model.is_open_do_not_disturb;
        } failure:^(NSString *error) {
            [MBProgressHUD showTopTipMessage:error];
        } hasCache:NO];
        
        
        
        
        block(responseObject);
    } failure:^(NSString *error, NSInteger code) {
        [[HUDHelper sharedInstance] syncStopLoading];
        [[HUDHelper sharedInstance] tipMessage:NSStringFormat(@"%@:%ld",error,code)];
    } hasCache:NO];
}

+(void)requestSubmitAuthInfoWith:(NSDictionary *)info andBlock:(CommonBlock)block
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"request_submit_auth_info"];
    NSMutableDictionary *param = [[NSMutableDictionary alloc] initWithDictionary:info];

    
    [CYNET POSTv3:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        block(responseObject);
    } failure:^(NSString *error, NSInteger code) {
        [[HUDHelper sharedInstance] tipMessage:NSStringFormat(@"%@:%ld",error,code)];
    } hasCache:NO];
}
@end
